package com.hn.birthdaymatch.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author Ts-SuSu
 * @date 2023/7/3 5:20
 * @description Swagger2配置类
 */
@Configuration
@EnableSwagger2
//@Profile({"dev","test"}) //Swagger在dev和test环境才生效
@ConditionalOnProperty(name = "swagger.enabled", havingValue = "true")
public class Swagger2Config {

    /**
     * swagger 隐藏 basic-error-controller
     *
     * @return
     */
    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("生日匹配系统")
                .apiInfo(webApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hn.birthdaymatch.controller"))
                .paths(PathSelectors.regex("(?!/error.*).*"))
                .build();
    }

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("生日匹配系统-API测试文档")
                //描述
                .description("寻找同年同月同日的TA")
                //版本
                .version("1.0")
                //维护人信息
                .contact(new Contact("Ts-SuSu", "https://www.tannic.fun", "TanNic1314@163.com"))
                .build();
    }
}